#define _CRT_SECURE_NO_WARNINGS
#include "biao.h"
void init(SL* q)
{
	q->arr = NULL;
	q->kong = 0;
	q->yuan = 0;
}
void get(SL* q)
{
	if (q->arr)
	{
		free(q->arr);
		q->arr = NULL;
	}
	q->kong = q->yuan = 0;
}
void pan(SL* q)
{
	if (q->yuan == q->kong)
	{
		int time = q->kong == 0 ? 4 : 2 * q->kong;
		leixing* temp = (leixing*)realloc(q->arr, time * sizeof(leixing));
		if (temp == NULL)
		{
			//perror("realloc temp");
			//exit(1);
		}
		q->arr = temp;
		q->kong = time;
	}
}
void weicha(SL*q,leixing x)
{
	assert(q);
	pan(q);
	q ->arr[q->yuan++] = x;
}
void toucha(SL* q, leixing x)
{
	assert(q);
	pan(q);
	for (int i=q->yuan;i>0;i--)
	{
		q->arr[i] = q->arr[i - 1];
	}
	q->arr[0] = x;
	q->yuan++;
}
void weixiao(SL* q)
{
	assert(q);
	assert(q->yuan); 
	q->yuan--;
}
void touxiao(SL* q)
{
	assert(q);
	assert(q->yuan);
	for (int i = 0; i < q -> yuan-1;i++)
	{
		q->arr[i] = q->arr[i + 1];  
	}
	q->yuan--;
}
//void SLprintf(SL q)
//{
//
//	for (int i = 0; i < q.yuan; i++)
//	{
//		printf("%d ", q.arr[i]);
//	}
//	printf("\n");
//}
void zdcha(SL* q, int wei, leixing x)
{
	assert(q);
	assert(wei>=0&&wei<=q->yuan);
	pan(q);
	for (int i = q->yuan; i >wei ; i--)
	{
		q->arr[i] = q->arr[i - 1];//
	}
	q->arr[wei] = x;
	q->yuan++;
}
void zdxiao(SL* q, int wei)
{
	assert(q);
	assert(wei >= 0 && wei < q->yuan);
	for (int i = wei; i < q->yuan - 1; i++)
	{
		q->arr[i] = q->arr[i + 1];
	}
	q->yuan--;
}
//int  chazhao(SL* q, leixing x)
//{
//	assert(q);
//	for (int i = 0; i < q->yuan; i++)
//	{
//		if (q->arr[i] == x)
//		{
//			return i;
//		}
//	} 
//	return -1;
//}